package struts.ext.util;

import java.util.Collection;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class Jsons {
	public static String toJson(Object o){
		if(o == null){
			return "";
		}
		
		if(o.getClass().isArray() || (o instanceof Collection<?>) || (o instanceof JSONArray)){
			return JSONArray.fromObject(o).toString();
		}
		
		return JSONObject.fromObject(o).toString();
	}
}
